package com.testing.Utlis;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Properties;


public class ReadPropertiesUtil {
    public static final Properties properties= new Properties();

    /**
     * 配置文件
     */
    private static final Properties PROPERTIES = new Properties();

    /**
     * 配置文件路径
     */
    public static final String FILEPATH = "src/main/resources/config/config.properties";

    /**
     * 私有化构造器，不允许外部构造
     */
    private ReadPropertiesUtil() {}

    /**
     * 读取 properties 测试项目配置文件
     *
     * @return PROPERTIES.getProperty(key);
     */
    public static String readProperties(String path, String key) {
        try {
            InputStream inputStream = new FileInputStream(path);
            // 读取配置文件通过 utf-8 编码方式读取
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            PROPERTIES.load(bufferedReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return PROPERTIES.getProperty(key);
    }
}
